package com.freen.fadmin.util;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

//将entity 调整的工具
//比如 格式化 Long 型字段 输出json 的格式
public class EntityUtils  extends JsonSerializer<Long>{
    @Override
    public void serialize(Long aLong, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        //首先是 Long 转 date
        Date date = new Date(aLong);
        //然后日志 格式化转 String
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
        String str = sdf.format(date);
        jsonGenerator.writeString(str);
        System.out.println(str);
    }
}

